---
description:
  Discover the power of GraphQL Mesh and PostGraphile with our handler library! Use your PostgreSQL
  database schema to create a GraphQL schema, and add external plugins for federation, many-to-many,
  and PostGIS support.
---

import { Callout } from '@theguild/components'

# PostgreSQL / PostGraphile

![image](https://user-images.githubusercontent.com/20847995/79219670-5ae06300-7e5b-11ea-81f1-d0c08a884607.png)

This handler allows you to use the GraphQL schema created by
[PostGraphile](https://graphile.org/postgraphile), based on a PostgreSQL database schema.

To get started, install the handler library:

```sh npm2yarn
npm i @graphql-mesh/postgraphile
```

Now, you can use it directly in your Mesh config file:

```yaml filename=".meshrc.yaml" {4-7}
sources:
  - name: MyDb
    handler:
      postgraphile:
        connectionString: postgres://postgres:password@localhost/postgres
        # You can also use environment variables like below
        # connectionString: postgres://{env.POSTGRES_USER}:{env.POSTGRES_PASSWORD}@localhost/postgres
```

<Callout>
  You can check out our example that uses schema stitching with a PostgreSQL data source. [Click
  here to open the example on
  GitHub](https://github.com/ardatan/graphql-mesh/tree/master/examples/postgres-geodb).
</Callout>

## External Plugins (e.g. FederationPlugin, PgManyToManyPlugin, PostGISPlugin)

You can add [PostGraphile plugins](https://graphile.org/postgraphile/community-plugins) for example
FederationPlugin. You can install it like below:

```sh npm2yarn
npm i @graphile/federation
```

and add those in your configuration file;

```yaml filename=".meshrc.yaml" {6-7}
sources:
  - name: MyDb
    handler:
      postgraphile:
        connectionString: postgres://postgres:password@localhost/postgres
        appendPlugins:
          - '@graphile/federation'
```

<Callout>
  Learn more about PostGraphile plugins [here](https://graphile.org/postgraphile/extending).
</Callout>

### Federation and Automatic Type Merging support

The Federation plugin converts your Postgraphile schema into a federated schema that can also be
recognized by Stitching, which brings Automatic Type Merging. So you can install
`@graphile/federation` package like above and add it under `appendPlugins`.

### Many-to-Many support

Suppose you want to have automatic many-to-many mapping across your entities. You can install
`@graphile-contrib/pg-many-to-many` and add it under `appendPlugins`.

```sh npm2yarn
npm i @graphile-contrib/pg-many-to-many
```

### PostGIS Support

If you use `PostGIS` in your PostgreSQL database, you need to install `@graphile/postgis` package
and add it under `appendPlugins`.

```sh npm2yarn
npm i @graphile/postgis
```

<Callout>
  See more [plugins](https://graphile.org/postgraphile/community-plugins) to improve the experience!
</Callout>

## Config API Reference

import API from '../../../generated-markdown/PostGraphileHandler.generated.md'

<API />
